package com.lc202407;

public class Solution724 {
    public int pivotIndex(int[] nums) {
        int left = 0;
        int right = 0;
        int length = nums.length;
        for (int i = 1; i < length; i++) {
            right += nums[i];
        }
        for (int i = 0; i < length; i++) {
            if (i > 0) {
                left += nums[i - 1];
                right -= nums[i];
            }
            if (left == right) {
                return i;
            }
        }
        return -1;
    }
}
